import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil;

import java.util.Arrays;
import java.util.Scanner;

public class Test {
    //数组逆序
    public static void main6(String[] args) {
        int[] array={1,2,3,4,5};
        int left=0;
        int right= array.length-1;
        while(left<right){
           int tmp=array[left];
           array[left]=array[right];
           array[right]=tmp;
           left++;
           right--;
        }
        System.out.println(Arrays.toString(array));
    }
    //冒泡排序
    public static void main(String[] args) {
        int[] array={1,4,5,2,6,3,9};
        int tmp=0;
        for (int i = 0; i < array.length; i++) {
            for (int j = 1; j < array.length-i; j++) {
                if(array[j-1]>array[j]){
                    tmp=array[j-1];
                    array[j-1]=array[j];
                    array[j]=tmp;
                }
            }
        }
        System.out.println(Arrays.toString(array));
    }
    //查找指定元素
    public static void main4(String[] args) {
        int[] array={1,2,3,4,5,6,7,8,9,10,11};
        Scanner scanner=new Scanner(System.in);
        int n= scanner.nextInt();
        int left=0;
        int right= array.length-1;
        while(left<=right){
            int middle=(left+right)>>>1;
            if(array[middle]>n){
                right=middle-1;
            } else if (array[middle]<n) {
                left=middle+1;
            } else if (array[middle]==n) {
                System.out.println("找到了");
                break;
            }
        }
    }

    //求平均值
    public static void main3(String[] args) {
        int[] array={1,2,3,4,5,6,7,8,9,10,11,23,45};
        float agv=0;
        for (int i = 0; i < array.length; i++) {
            agv=agv+array[i];
        }
        System.out.println(agv/ array.length);
    }
    //拷贝数组
    public static void main2(String[] args) {
        int[] arrays={1,3,5,7,9};
        int[] arrays1=Copy(arrays);
        System.out.print("[");
        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays1[i]);
            if(i!= arrays.length-1){
                System.out.print(",");
            }
        }
        System.out.print("]");
        System.out.println(Arrays.toString(arrays1));
    }
    public static int[] Copy(int[] arr){
        int[] arr1=new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            arr1[i]=arr[i];
        }
        return arr1;
    }


    public static void main1(String[] args) {
        int[] arr={1,2,3,4,5,6};
        String ret=myToString(arr);
        System.out.println(ret);
    }
    public static String myToString(int[] arr){
        if(arr==null){
        return "null";
    }String ret = "[";
        for (int i = 0; i < arr.length; i++) {
            ret=ret+arr[i];
            if(i!=arr.length-1){
                ret=ret+",";
            }
        }ret=ret+"]";
        return ret;
    }

}
